package com.aaa.controller;

import com.aaa.entity.Roomtype;
import com.aaa.service.RoomtypeService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("roomtype")
@RestController
public class RoomtypeController {
    @Resource
    private RoomtypeService roomtypeService;

    /**
     * 查询全部房间类型
     *
     * @return
     */
    @RequestMapping("findtype")
    private List<Map<String, Object>> findtype() {
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        map.put("id", "");
        map.put("typename", "全部房间类型");
        list.add(map);
        for (int i = 0; i < roomtypeService.findtype().size(); i++) {
            list.add(roomtypeService.findtype().get(i));
        }
        return list;
    }


    /**
     * 分页模糊查询
     *
     * @param typename 值
     * @param pageNum  当前页
     * @param pageSize 每页几条数据
     * @return
     */
    @RequestMapping("find")
    public PageInfo<Roomtype> find(String typename, Integer pageNum, Integer pageSize) {

        return roomtypeService.roomfind(typename,pageNum,pageSize);
    }



    /**
     * 添加方法
     *
     * @param roomtype
     * @return 返回数据
     */
    @RequestMapping("add")
    public Integer add(Roomtype roomtype) {
        System.out.println(roomtype);
        return roomtypeService.add(roomtype);
    }

    /**
     * 根据id查询房间类型
     *
     * @param id id主键唯一性
     * @return 结果
     */
    @RequestMapping("toedit")
    public Roomtype toedit(Integer id) {
        return roomtypeService.toedit(id);
    }

    @RequestMapping("update")
    public Integer update(Integer id, String typename, String img, String money, String remark) {
        Roomtype roomtype = new Roomtype(id, typename, img, money, null, remark);
        System.out.println(roomtype);
        return roomtypeService.update(roomtype);
    }

    /**
     * 前台请求返回数据
     *
     * @param typename 房间类型数据值
     * @return 返回业务层处理
     */
    @RequestMapping("query")
    public List<Map<String, Object>> query(Integer id,String typename) {
        return roomtypeService.query(id,typename);
    }
    @RequestMapping("findalltype")
    private List<Map<String,Object>> findalltype(){
        return roomtypeService.findtype();
    }
    @RequestMapping("choicedate")
    private Object choicedate(String choiceEnddate,Integer rid,Integer odid) throws ParseException {
        System.out.println(choiceEnddate);
        return roomtypeService.choicedate(choiceEnddate,rid,odid);
    }
}
